﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Resources;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Converter;
using csla4Skeleton.UI.SL.Resources.Utility;
using csla4Skeleton.UI.SL.NghiepVu.TaiSanCoDinh.DM_DoiTuongTHCP;
using csla4Skeleton.UI.SL.DanhMuc.DM_HangHoa;
using csla4Skeleton.UI.SL.NghiepVu.TinhGiaThanh.GT_KyGiaThanh;
using csla4Skeleton.UI.SL.DanhMuc.DM_TaiKhoan;
using Accounting.Library;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows;
using System.ComponentModel;
using Utility;
using Accounting.Library.Utility;
using csla4Skeleton.UI.SL.NghiepVu.TinhGiaThanh.GT_KyGiaThanh;
using csla4Skeleton.UI.SL.NghiepVu.TinhGiaThanh.GT_SoLuongSPDD;
using csla4Skeleton.UI.SL.NghiepVu.TinhGiaThanh.GT_CPPhanBo;
using csla4Skeleton.UI.SL.NghiepVu.TinhGiaThanh.GT_CPTrucTiep;
using csla4Skeleton.UI.SL.NghiepVu.TinhGiaThanh.GT_DoDangDK;


namespace csla4Skeleton.UI.SL.NghiepVu.TinhGiaThanh.GT_DoDangCK
{
    public partial class GT_DoDangCK_MainWindow: UserControl, Csla.Xaml.ISupportNavigation
    {

        #region ISupportNavigation Members
        List<Control> controls = new List<Control>();
        public bool CreateBookmarkAfterLoadCompleted
        {
            get { return true; }
        }

        public event EventHandler LoadCompleted;

        protected virtual void OnLoadCompleted()
        {
            if (LoadCompleted != null)
                LoadCompleted(this, EventArgs.Empty);
        }

        public void SetParameters(string parameters)
        {
            try
            {
                if (parameters == "")
                    Khoa = null;
                else
                    Khoa = Int32.Parse(parameters);
            }
            catch
            {
                Khoa = null;
            }
        }

        public string Title
        {
            get { return "DoDangCK"; }
        }

       
        #endregion

        #region Load Methods
        private System.Nullable<int> Khoa = null;
        List<GT_KyGiaThanhInfo> ResultList = new List<GT_KyGiaThanhInfo>();
        public GT_DoDangCK_MainWindow(int Khoa)          
        {
            this.Khoa = Khoa;
           
        }

        public GT_DoDangCK_MainWindow()
        {
            LocalizationConverter converter = new LocalizationConverter();
            converter.LocalResourceManager = new ResourceManager("csla4Skeleton.UI.SL.NghiepVu.TinhGiaThanh.GT_DoDangCK.Resources", Assembly.GetExecutingAssembly());
            this.Resources.Add("Localization", converter);
            
            InitializeComponent();  
            ControlBehavior.ControlBehaviors.Navigation(this.GT_DoDangCK_ChungTuInformation_GroupBox, controls);
           
           
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                
                System.Windows.Data.CollectionViewSource GT_DoDangCK_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_DoDangCK_ViewModelSource"];
                if (Khoa == null)
                {
                    GT_DoDangCK_ViewModel GT_DoDangCK_ViewModel = new GT_DoDangCK_ViewModel();
                    GT_DoDangCK_ViewModel.ChildList_AddedNew += new GT_DoDangCK_ViewModel.ChildList_AddedNew_EventHandler(GT_DoDangCK_ViewModel_ChildList_AddedNew);
                    GT_DoDangCK_ViewModel.KyGiaThanhIdChanged += new EventHandler(OnKyGiaThanhIdChanged);
                    GT_DoDangCK_CollectionViewSource.Source = new List<object> { GT_DoDangCK_ViewModel };

                    
                }
                else
                {
                    GT_DoDangCK_ViewModel GT_DoDangCK_ViewModel = new GT_DoDangCK_ViewModel((int)Khoa);
                    GT_DoDangCK_ViewModel.ChildList_AddedNew += new GT_DoDangCK_ViewModel.ChildList_AddedNew_EventHandler(GT_DoDangCK_ViewModel_ChildList_AddedNew);
                    GT_DoDangCK_ViewModel.KyGiaThanhIdChanged += new EventHandler(OnKyGiaThanhIdChanged);
                    GT_DoDangCK_CollectionViewSource.Source = new List<object> { GT_DoDangCK_ViewModel };

                    
                }

                System.Windows.Data.CollectionViewSource dm_DoiTuongTHCP_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_DoiTuongTHCP_ListViewModelSource"];
                DM_DoiTuongTHCP_ListViewModel dm_DoiTuongTHCP_ListViewModel = new DM_DoiTuongTHCP_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
                dm_DoiTuongTHCP_CollectionViewSource.Source = new List<object> { dm_DoiTuongTHCP_ListViewModel };

               
                System.Windows.Data.CollectionViewSource dm_HangHoa_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_HangHoa_ListViewModelSource"];
                DM_HangHoa_ListViewModel dm_HangHoa_ListViewModel = new DM_HangHoa_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
                dm_HangHoa_CollectionViewSource.Source = new List<object> { dm_HangHoa_ListViewModel };

               
                System.Windows.Data.CollectionViewSource gt_KyGiaThanh_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_KyGiaThanh_ListViewModelSource"];
                GT_KyGiaThanh_ListViewModel gt_KyGiaThanh_ListViewModel = new GT_KyGiaThanh_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
                gt_KyGiaThanh_CollectionViewSource.Source = new List<object> { gt_KyGiaThanh_ListViewModel };

                System.Windows.Data.CollectionViewSource gt_KyGiaThanh_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_KyGiaThanh_ChiTiet_ListViewModelSource"];
                GT_KyGiaThanh_ListViewModel gt_KyGiaThanh_ChiTiet_ListViewModel = new GT_KyGiaThanh_ListViewModel(BusinessConfiguration.Configuration.KyGiaThanhFilterMode);
                gt_KyGiaThanh_ChiTiet_CollectionViewSource.Source = new List<object> { gt_KyGiaThanh_ChiTiet_ListViewModel };

                System.Windows.Data.CollectionViewSource gt_DoDangDK_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_DoDangDK_ListViewModelSource"];
                GT_DoDangDK_ListViewModel gt_DoDangDK_ListViewModel = new GT_DoDangDK_ListViewModel(BusinessConfiguration.Configuration.DoDangDKFilterMode);
                gt_DoDangDK_CollectionViewSource.Source = new List<object> { gt_DoDangDK_ListViewModel };

                System.Windows.Data.CollectionViewSource gt_SoLuongSPDD_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_SoLuongSPDD_ListViewModelSource"];
                GT_SoLuongSPDD_ListViewModel gt_SoLuongSPDD_ListViewModel = new GT_SoLuongSPDD_ListViewModel(BusinessConfiguration.Configuration.SoLuongSPDDFilterMode);
                gt_SoLuongSPDD_CollectionViewSource.Source = new List<object> { gt_SoLuongSPDD_ListViewModel };


                System.Windows.Data.CollectionViewSource gt_CPTrucTiep_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_CPTrucTiep_ListViewModelSource"];
                GT_CPTrucTiep_ListViewModel gt_CPTrucTiep_ListViewModel = new GT_CPTrucTiep_ListViewModel(BusinessConfiguration.Configuration.CPTrucTiepFilterMode);
                gt_CPTrucTiep_CollectionViewSource.Source = new List<object> { gt_CPTrucTiep_ListViewModel };

                System.Windows.Data.CollectionViewSource gt_CPPhanBo_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_CPPhanBo_ListViewModelSource"];
                GT_CPPhanBo_ListViewModel gt_CPPhanBo_ListViewModel = new GT_CPPhanBo_ListViewModel(BusinessConfiguration.Configuration.CPPhanBoFilterMode);
                gt_CPPhanBo_CollectionViewSource.Source = new List<object> { gt_CPPhanBo_ListViewModel };


                this.GT_DoDangCK_DoDangCKChiTietGridView.KeyboardCommandProvider = new ControlBehavior.GridViewKeyboardCommandProvider(this.GT_DoDangCK_DoDangCKChiTietGridView);
                
                ((ControlBehavior.GridViewKeyboardCommandProvider)this.GT_DoDangCK_DoDangCKChiTietGridView.KeyboardCommandProvider).ReachLastColumn += new ControlBehavior.GridViewKeyboardCommandProvider.ReachLastColumn_EventHandler(OnReachLastColumn);

                ((ControlBehavior.GridViewKeyboardCommandProvider)this.GT_DoDangCK_DoDangCKChiTietGridView.KeyboardCommandProvider).TabKeyPress += new EventHandler(OnTabKeyPress);
            }
        }

        #endregion
       

        #region Event Handle
        private void LayoutRoot_KeyUp(object sender, KeyEventArgs e)
        {
            if (Keyboard.Modifiers == ModifierKeys.Control)
            {
                GT_DoDangCK_ViewModel vm = GetViewModel();
                if (e.Key == Key.S)
                {
                    if (vm.CanSave)
                    {
                        vm.Save(sender, new Csla.Xaml.ExecuteEventArgs());
                    }
                }
                else if (e.Key == Key.F6)
                {
                    AddItems();
                }
                else if (e.Key == Key.D1)
                {
                    this.GT_DoDangCK_DoDangCKChiTietTab.IsSelected = true;
                }
               
               
                
            }
            e.Handled = true;
        }

        void AddItemButton_Click(object sender, RoutedEventArgs e)
        {

            AddItems();
        }

        void DeleteItemButton_Click(object sender, RoutedEventArgs e)
        {
            DeleteItems();
          
        }

        public void AddItems()
        {
            if (this.GT_DoDangCK_DoDangCKChiTietTab.IsSelected)
            {
                AddDoDangCKDetailsItem();
            }
        }
        private RadGridView GetActiveGridView()
        {
            if (this.GT_DoDangCK_DoDangCKChiTietTab.IsSelected)
            {
                return GT_DoDangCK_DoDangCKChiTietGridView;
            }
           
            return null;
        }



        void DeleteItems()
        {
           if (this.GT_DoDangCK_DoDangCKChiTietTab.IsSelected)
            {
                GT_DoDangCK_ChiTietChild ChiTietChild = (GT_DoDangCK_ChiTietChild)(this.GT_DoDangCK_DoDangCKChiTietGridView.SelectedItem);
                IList<GT_DoDangCK_ChiTietChild> list = GetViewModel().Model.GT_DoDangCK_ChiTiets;
                int index = list.IndexOf(ChiTietChild);
                DeleteDoDangCKDeTailsItem(index);
            }
           
            
        }
           
        void GridView_AddingNewDataItem(object sender, GridViewAddingNewEventArgs e)
        {
            var grid = e.OwnerGridViewItemsControl;
            if (grid.Items.Count > 0)
            {
                GridViewUtil.FocusRow((RadGridView)grid, grid.Items.Count - 1);
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    grid.CurrentCellInfo = new GridViewCellInfo(grid.Items[grid.Items.Count - 1], grid.Columns[0]);
                    grid.Focus();
                    grid.BeginEdit();
                }));
            }
        }
              
        private void SaveAndNewButton_Click(object sender, RoutedEventArgs e)
        {
           GT_DoDangCK_ViewModel vm = GetViewModel();
            vm.SaveAndNew();
        }

        private void DatePicker_KeyUp(object sender, KeyEventArgs e)
        {
            List<Control> availableControl = new List<Control>();
            foreach (Control item in controls)
            {
                if (item.Visibility == System.Windows.Visibility.Visible)
                {
                    availableControl.Add(item);
                }
            }
            Control[] list = availableControl.ToArray();
            if (sender.GetHashCode() == list[availableControl.Count - 1].GetHashCode())
            {
                if (e.Key == Key.Enter)
                {
                    this.AddDoDangCKDetailsItem();
                }
            }
            else
            {
                ControlBehavior.DatePickerBehaviors.DatePicker_KeyUp(sender, e, controls);
            }
        }

        private void ComboBox_KeyUp(object sender, KeyEventArgs e)
        {
            List<Control> availableControl = new List<Control>();
            foreach (Control item in controls)
            {
                if (item.Visibility == System.Windows.Visibility.Visible)
                {
                    availableControl.Add(item);
                }
            }
            Control[] list = availableControl.ToArray();
            if (sender.GetHashCode() == list[availableControl.Count - 1].GetHashCode())
            {
                if (e.Key == Key.Enter)
                {
                    this.AddDoDangCKDetailsItem();
                }
            }
            else
            {
                ControlBehavior.ComboBoxBehaviors.ComboBox_KeyUp(sender, e, controls);
            }
        }

        private void Control_KeyUp(object sender, KeyEventArgs e)
        {
            List<Control> availableControl = new List<Control>();
            foreach (Control item in controls)
            {
                if (item.Visibility == System.Windows.Visibility.Visible)
                {
                    availableControl.Add(item);
                }
            }
            Control[] list = availableControl.ToArray();
            if (sender.GetHashCode() == list[availableControl.Count - 1].GetHashCode())
            {
                if (e.Key == Key.Enter)
                {
                    this.AddDoDangCKDetailsItem();
                }
            }
            else
            {
                ControlBehavior.ControlBehaviors.Control_KeyUp(sender, e, controls);
            }
        }

        void OnTabKeyPress(object sender, EventArgs e)
        {
            this.tabControl.SelectedItem = tabControl.Items[0];
            this.AddDoDangCKDetailsItem();
        }


        void OnReachLastColumn(object sender, ReachLastColumnArgs e)
        {

            List<TabItem> AvailableTabItem = new List<TabItem>();
            int indexCurrentTab = 0;
            foreach (TabItem item in this.tabControl.Items)
            {
                if (item.Visibility == System.Windows.Visibility.Visible)
                {
                    AvailableTabItem.Add(item);
                    if (item.GetHashCode() == tabControl.SelectedItem.GetHashCode())
                    {
                        indexCurrentTab = AvailableTabItem.IndexOf(item);
                    }

                }
            }


            TabItem[] list = AvailableTabItem.ToArray();
            if (indexCurrentTab == (AvailableTabItem.Count - 1))
            {
                this.tabControl.SelectedItem = list[0];
                FocusAfterChangeTab(this.GT_DoDangCK_DoDangCKChiTietGridView, e.Index);

            }
            

        }

        private void FocusAfterChangeTab(GridViewDataControl grid, int index)
        {
             
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    grid.CurrentCellInfo = new GridViewCellInfo(grid.Items[index], grid.Columns[0]);
                    grid.Focus();
                    grid.BeginEdit();
                }));
           
        }
        
        
       
        #endregion

        #region View Model Related Methods
        private GT_DoDangCK_ViewModel GetViewModel()
        {
            System.Windows.Data.CollectionViewSource GT_DoDangCK_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_DoDangCK_ViewModelSource"];
            return ((List<object>)GT_DoDangCK_CollectionViewSource.Source)[0] as GT_DoDangCK_ViewModel;
        }


        private void AddDoDangCKDetailsItem()
        {
            GetViewModel().AddGT_DoDangCK_ChiTietItem();
        }
        private void DeleteDoDangCKDeTailsItem(int Index)
        {
            GetViewModel().DeleteGT_DoDangCK_ChiTietItem( Index);
        }

        void OnKyGiaThanhIdChanged(object sender, EventArgs e)
        {
            
            System.Windows.Data.CollectionViewSource gt_KyGiaThanh_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_KyGiaThanh_ChiTiet_ListViewModelSource"];
            GT_KyGiaThanh_ListViewModel gt_KyGiaThanh_ListViewModel = new GT_KyGiaThanh_ListViewModel(BusinessConfiguration.Configuration.KyGiaThanhFilterMode);
            gt_KyGiaThanh_ListViewModel.LoadCompleted += new EventHandler(OnKyGiaThanhChiTietLoadCompleteted);
            gt_KyGiaThanh_CollectionViewSource.Source = new List<object> { gt_KyGiaThanh_ListViewModel };

        }

        
        void OnKyGiaThanhChiTietLoadCompleteted(object sender, EventArgs e)
        {
            IList<GT_DoDangCK_ChiTietChild> listChiTiet = this.GetViewModel().Model.GT_DoDangCK_ChiTiets;
            while (listChiTiet.Count != 0)
            {
                this.DeleteDoDangCKDeTailsItem(0);
            }

            System.Windows.Data.CollectionViewSource gt_KyGiaThanh_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_KyGiaThanh_ChiTiet_ListViewModelSource"];
            GT_KyGiaThanh_ListViewModel gt_KyGiaThanh_ListViewModel = ((List<object>)gt_KyGiaThanh_CollectionViewSource.Source)[0] as GT_KyGiaThanh_ListViewModel;
            IList<GT_KyGiaThanhInfo> listKyGiaThanh = gt_KyGiaThanh_ListViewModel.Model.getListOfInfo();

            foreach (GT_KyGiaThanhInfo item in listKyGiaThanh)
            {
                if (item.Khoa == this.GetViewModel().Model.KyGiaThanhId)
                {
                    ResultList.Add(item);
                    this.AddDoDangCKDetailsItem();
                }
            }
            this.GetViewModel().CountChanged += new EventHandler(OnCountChanged);
        }

        
        void OnCountChanged(object sender, EventArgs e)
        {
            IList<GT_DoDangCK_ChiTietChild> listChiTiet = GetViewModel().Model.GT_DoDangCK_ChiTiets;

            System.Windows.Data.CollectionViewSource gt_DoDangDK_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_DoDangDK_ListViewModelSource"];
            GT_DoDangDK_ListViewModel gt_DoDangDK_ListViewModel = ((List<object>)gt_DoDangDK_CollectionViewSource.Source)[0] as GT_DoDangDK_ListViewModel;
            IList<GT_DoDangDKInfo> listDoDangDK = gt_DoDangDK_ListViewModel.Model.getListOfInfo();

            System.Windows.Data.CollectionViewSource gt_CPTrucTiep_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_CPTrucTiep_ListViewModelSource"];
            GT_CPTrucTiep_ListViewModel gt_CPTrucTiep_ListViewModel = ((List<object>)gt_CPTrucTiep_CollectionViewSource.Source)[0] as GT_CPTrucTiep_ListViewModel;
            IList<GT_CPTrucTiepInfo> listCPTrucTiep = gt_CPTrucTiep_ListViewModel.Model.getListOfInfo();

            System.Windows.Data.CollectionViewSource gt_CPPhanBo_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_CPPhanBo_ListViewModelSource"];
            GT_CPPhanBo_ListViewModel gt_CPPhanBo_ListViewModel = ((List<object>)gt_CPPhanBo_CollectionViewSource.Source)[0] as GT_CPPhanBo_ListViewModel;
            IList<GT_CPPhanBoInfo> listCPPhanBo = gt_CPPhanBo_ListViewModel.Model.getListOfInfo();

            System.Windows.Data.CollectionViewSource gt_SoLuongSPDD_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["GT_SoLuongSPDD_ListViewModelSource"];
            GT_SoLuongSPDD_ListViewModel gt_SoLuongSPDD_ListViewModel = ((List<object>)gt_SoLuongSPDD_CollectionViewSource.Source)[0] as GT_SoLuongSPDD_ListViewModel;
            IList<GT_SoLuongSPDDInfo> listSoLuongSPDD = gt_SoLuongSPDD_ListViewModel.Model.getListOfInfo();

            if (listChiTiet.Count == ResultList.Count)
            {
                GT_KyGiaThanhInfo[] KyGiaThanhArray = ResultList.ToArray();
                int index = 0;
                foreach (GT_DoDangCK_ChiTietChild item in listChiTiet)
                {
                    item.DoiTuongTHCPId = KyGiaThanhArray[index].DoiTuongTHCPId;
                    item.HangHoaId = KyGiaThanhArray[index].HangHoaId;

                    foreach (GT_DoDangDKInfo DoDangDKItem in listDoDangDK)
                    {
                        if (DoDangDKItem.HangHoaId == item.HangHoaId && DoDangDKItem.DoiTuongTHCPId == item.DoiTuongTHCPId
                            && DoDangDKItem.KyGiaThanhId == this.GetViewModel().Model.KyGiaThanhId)
                        {
                            item.DoDangDK = DoDangDKItem.TongCong;
                            break;
                        }
                    }

                    double? TongCongCPTrucTiep = 0;
                    foreach (GT_CPTrucTiepInfo CPTrucTiepItem in listCPTrucTiep)
                    {
                        if (CPTrucTiepItem.HangHoaId == item.HangHoaId && CPTrucTiepItem.DoiTuongTHCPId == item.DoiTuongTHCPId
                            && CPTrucTiepItem.KyGiaThanhId == this.GetViewModel().Model.KyGiaThanhId)
                        {
                            if (CPTrucTiepItem.TongCong != null)
                            {
                                TongCongCPTrucTiep = CPTrucTiepItem.TongCong;
                            }
                            break;
                        }
                    }

                    double? TongCongCPPhanBo = 0;
                    foreach (GT_CPPhanBoInfo CPPhanBoItem in listCPPhanBo)
                    {
                        if (CPPhanBoItem.HangHoaId == item.HangHoaId && CPPhanBoItem.DoiTuongTHCPId == item.DoiTuongTHCPId
                            && CPPhanBoItem.KyGiaThanhId == this.GetViewModel().Model.KyGiaThanhId)
                        {
                            if (CPPhanBoItem.TongCong != null)
                            {
                                TongCongCPPhanBo = CPPhanBoItem.TongCong;
                            }
                            break;
                        }
                    }
                    item.PhatSinhTK = TongCongCPPhanBo + TongCongCPTrucTiep;

                    foreach (GT_SoLuongSPDDInfo SoLuongSPDDItem in listSoLuongSPDD)
                    {
                        if (SoLuongSPDDItem.HangHoaId == item.HangHoaId && SoLuongSPDDItem.DoiTuongTHCPId == item.DoiTuongTHCPId
                            && SoLuongSPDDItem.KyGiaThanhId == this.GetViewModel().Model.KyGiaThanhId)
                        {
                            if (KyGiaThanhArray[index].SoLuongNK != null && SoLuongSPDDItem.SoLuong != null
                                && SoLuongSPDDItem.TyLeHoanThanh != null && SoLuongSPDDItem.SoLuong != null
                                && item.DoDangDK != null && item.PhatSinhTK != null)
                            {
                                if (KyGiaThanhArray[index].SoLuongNK + SoLuongSPDDItem.SoLuong * SoLuongSPDDItem.TyLeHoanThanh != 0)
                                {
                                    item.DoDangCK = ((item.DoDangDK + item.PhatSinhTK) / (KyGiaThanhArray[index].SoLuongNK + SoLuongSPDDItem.SoLuong * SoLuongSPDDItem.TyLeHoanThanh))
                                                    * SoLuongSPDDItem.SoLuong * SoLuongSPDDItem.TyLeHoanThanh;
                                    break;
                                }
                            }

                        }
                    }

                    index++;
                }
                
            }
          
           
        }

        void GT_DoDangCK_ViewModel_ChildList_AddedNew(object sender, ChildListAddedNewArgs e)
        {
            if (e.ChildListName == "GT_DoDangCK_ChiTiets")
            {
                this.GT_DoDangCK_DoDangCKChiTietGridView.OnAddingNewDataItem(new GridViewAddingNewEventArgs(GetActiveGridView()));
            }
        }

       
        #endregion
        
    }
}
